import lookup from "./lookup";
import parseArray from "./parseArray";

// 将tokens数组，注入数据后，转换成字符串输出
export default function injectData (tokens, data) {
    let str = ''
    tokens.forEach(token => {
        if (token[0] === 'text') {
            str += token[1]
        }
        else if (token[0] === 'name') {
            str += lookup(data, token[1])
        }
        else if (token[0] === '#') {
            str += parseArray(token, data)
        }
    })
    return str
}